<template>
  <div class="container">
    <div class="exam-item" v-for="item in pageList">
      <h2 class="exam-item-title hidetxt">{{item.info}}</h2>
      <div class="exam-time">考试时间：{{item.papersc}}分钟</div>
      <div class="exam-item-bottom">
        <div class="exam-total">考试时段：{{item.startime | timeFormat('yyyy-mm-dd')}} - {{item.endtime | timeFormat('yyyy-mm-dd')}}</div>
        <!--<router-link  :to="{path:'/examinationDetail',query: {id: item.id}}" tag="button">开始考试</router-link>-->
        <button v-if="item.pg_score === 999999" class="btn-to-exam" @click="startExam(item)">开始考试</button>
        <span class="score" v-else>{{item.pg_score}}分</span>
      </div>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
  import util from '@/common/util';
  export default {
    data(){
      return {
        id: '',
        idcard: '',
        pageList: [],
      }
    },
    created() {
      let that = this;
      that.id = that.$route.query.id;
      if(util.storage.get('userinfo')){
        that.idcard = util.storage.get('userinfo').idcard;
      }
      console.log('id',that.id)
      console.log('idcard',that.idcard)
      that.getPageList();
    },
    // beforeRouteLeave(to, from, next){
    //   console.log('to',to)
    //   if(to.path == "/examinationDetail"){
    //     this.$router.push({path:"/examinationList"});
    //   }else{
    //     next();
    //   }
    // },
    methods: {
      getPageList() {
        let that = this;
        that.$api.post('/mobile/Kcks/pagelist', {'user':{'id':that.id,'idcard':that.idcard}}, r => {
          console.log(r)
          that.pageList = r.data.list;
        })
      },
      startExam(e) { //开始考试
        let that = this;
        let nowTimestamp = Math.round(new Date() / 1000) ;
        console.log('当前时间：',nowTimestamp);
        if(nowTimestamp < e.startime){
          that.$toast("考试时间未开始！")
        } else if(nowTimestamp > e.endtime){
          that.$toast("考试时间已过！")
        } else {
          that.$router.push({path:'/examinationDetail',query: {id: e.id}})
        }
      }
    }
  }
</script>

<style scoped>

</style>
